package com.wei.czz.common.vo.admin.deptUser;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.wei.czz.common.constant.Constant;
import com.wei.czz.common.constant.EntityConstant;
import com.wei.czz.common.constant.RedisConstant;
import com.wei.czz.common.vo.common.BaseVo;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Optional;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-08-24 21:22:16
 * className: DeptUserFormVo 部门关联用户请求表单对象
 * version: 1.0
 * description:
 */
@Getter
@Setter
public class DeptUserFormVo extends BaseVo {

    /**
     * 部门主键
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deptId;

    /**
     * 联系方式
     * 匹配手机号和邮箱号
     */
    private String contact;

    /**
     * 是否领导状态[0-是 1-否]
     */
    private Integer leaderStatus;

    /**
     * 手机号
     * 代码内赋值
     */
    @JsonIgnore
    private String phone;

    /**
     * 邮箱号
     * 代码内赋值
     */
    @JsonIgnore
    private String email;

    /**
     * 部门主键列表
     * 代码内赋值
     */
    @JsonIgnore
    private List<Long> deptIdList;

    /**
     * 构造用户列表分布式锁键
     * @return 键值
     */
    @JsonIgnore
    public String getUserListKey() {
        String deptIds = Optional.ofNullable(deptIdList).map(list -> StringUtils.join(deptIdList, ","))
                .orElse(null);
        return RedisConstant.STRING + EntityConstant.USER + Constant.UNDER + RedisConstant.LIST + deptIds
                + RedisConstant.SPLIT + word + RedisConstant.SPLIT + contact + Constant.SPLIT + leaderStatus
                + RedisConstant.SPLIT + phone + Constant.SPLIT + email + RedisConstant.SPLIT + status
                + RedisConstant.SPLIT + page + RedisConstant.SPLIT + limit + RedisConstant.SPLIT + field
                + RedisConstant.SPLIT + order;
    }

}
